-@title = "CMS Reg Mapper for: #{@program.title}"

-content_for :header do
  %ol#breadcrumb
    %li=link_to 'Programs', programs_dash_path
    %li Mapping
  .location#pageTitle=@program.title

-content_for :page_help, 'mapping'

-content_for :subheader_extras do
  %h1.fltrt.highlighted Regulation to Control Mapping

.row-static
  .singleColumn
    .singleWide.halfHeight#section_list
      =render :partial => 'section_list',
              :layout => 'layouts/widget_box',
              :locals => { :sections => @program.sections.includes(:parent, :controls => :implementing_controls) }
    .singleWide.maxhalfHeight
      =render :partial => 'selected_section',
              :layout => 'layouts/widget_box',
              :locals => {:section => nil}
 
  .singleColumn
    .singleWide.halfHeight#rcontrol_list
      =render :partial => 'control_list',
              :layout => 'layouts/widget_box',
              :locals => { :controls => @rcontrols, :title_prefix => 'Reg', :control_type => 'regulation' }

    .singleWide.maxhalfHeight
      =render :partial => 'selected_control',
              :layout => 'layouts/widget_box',
              :locals => {:control => nil, :control_type => 'rcontrol', :map_button_id => :cmap, :map_button_path => mapping_map_ccontrol_path }

  .singleColumn
    .singleWide.halfHeight#ccontrol_list
      =render :partial => 'control_list',
              :layout => 'layouts/widget_box',
              :locals => { :controls => @ccontrols, :title_prefix => 'Company', :control_type => 'company' }

    .singleWide.maxhalfHeight
      =render :partial => 'selected_control',
              :layout => 'layouts/widget_box',
              :locals => {:control => nil, :control_type => 'ccontrol', :map_button_id => nil }

:javascript
  $(document).ready(function(){
    init_mapping();
  });
  function update_map_buttons() {
    update_map_buttons_with_path('#{mapping_buttons_path(:format => "json")}');
  }

#create-rcontrol-modal.modal.hide.fade
  -control = Control.new(:program => @program)
  =form_for control, :url => mapping_create_rcontrol_path, :method => :post, :remote => true, :html => {:class => :form} do |f|
    .modal-header
      %a.close{"data-dismiss" => "modal"} x
      %h1 Create a new regulation control
    .modal-body
      =render :partial => 'controls/form',
              :locals  => { :f => f }
    .modal-footer
      =f.submit pat(:save)
      =f.submit pat(:cancel), :type => 'reset'

#create-ccontrol-modal.modal.hide.fade
  -control = Control.new
  =form_for control, :url => mapping_create_ccontrol_path, :method => :post, :remote => true, :html => {:class => :form} do |f|
    .modal-header
      %a.close{"data-dismiss" => "modal"} x
      %h1 Create a new company control
    .modal-body
      =render :partial => 'controls/form',
              :locals  => { :f => f }
    .modal-footer
      =f.submit pat(:save)
      =f.submit pat(:cancel), :type => 'reset'
